﻿#include "BrowserTableHandlerSubsystemDoublyShell.h"
#include "OperatorsInterface/OperAbstractSubsystem.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEASubSys.h"


namespace GUI
{
    void BrowserTableHandlerSubsystemDoublyShell::updateTable()
    {
        if (_tableWidget == nullptr) return;
        _tableWidget->clear();
        _tableWidget->setColumnCount(0);
        _tableWidget->setRowCount(0);

        //设置表头
        QStringList headerLabels;
        headerLabels << tr("Name") << tr("Physical Properties") << tr("Flexural DLF")
            << tr("Area[m2]") << tr("Thickness[m]") << tr("Perimeter[m]") << tr("Mass[kg]")
            << tr("Treatment Face +Z") << tr("Treatment Face -Z") << tr("Radius R1[m]")
            << tr("Radius R2[m]") << tr("Notes");
        _tableWidget->setColumnCount(headerLabels.size());
        _tableWidget->setHorizontalHeaderLabels(headerLabels);
        //更新表格
        this->updateData();
    }
    void BrowserTableHandlerSubsystemDoublyShell::updateData()
    {
        if (_tableWidget == nullptr) return;
        if (_seaMgr == nullptr || _propMgr == nullptr)return;

        QList<Acoustics::FITKAbstractSEASubSys*> list = _seaMgr->getSubSysByType(
            Acoustics::FITKAbstractSEASubSys::SEADoublyCurvedShell);
        updateLine(&list);
        _tableWidget->autoResizeCellWidth();
        _tableWidget->setTableItemEditable(false);
    }
    EventOper::OperAbstractSubsystem * BrowserTableHandlerSubsystemDoublyShell::getSubsystemOper()
    {
        //从操作器仓库获取
        return Core::FITKOperatorRepo::getInstance()->
            getOperatorT<EventOper::OperAbstractSubsystem>("OperSubsystemDoublyCurvedShell");
    }
    bool BrowserTableHandlerSubsystemDoublyShell::enableAttriSet()
    {
        QList<QTableWidgetItem*> selectItems = this->getSelectItems();
        if (selectItems.size() < 2) return false;

        QTableWidgetItem* item = selectItems.at(0);
        if (item == nullptr) return false;
        //名称列
        const int colIndex = item->column();
        //板材料，频谱，内外声学包种类
        if (!(colIndex == 1 || colIndex == 2 || colIndex == 7 || colIndex == 8)) return false;

        return true;
    }
}